package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.activitis.BaseActivity;
import com.sxm.yiwei.activitis.ChooseAliAcount;
import com.sxm.yiwei.activitis.MyAccountStream;
import com.sxm.yiwei.beans.AcountListBeans;
import com.sxm.yiwei.beans.Stream;

import java.util.List;

/**
 * Created by KuKa on 2017/8/11.
 * 账户列表
 */

public class AccountAdapter extends BaseAdapter {
    Context context;
    public List<AcountListBeans.DataBean> acountlist;
    OnClickListenerEditOrDelete onClickListenerEditOrDelete;
    public AccountAdapter(Context context, List<AcountListBeans.DataBean> acountlist) {
        this.context=context;
        this.acountlist=acountlist;
    }



    @Override
    public int getCount() {
        return acountlist.size();
    }

    @Override
    public Object getItem(int position) {
        return acountlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
         ViewHolder holder ;
        if (convertView==null){
            view = View.inflate(context, R.layout.choose_item,null);
            holder = new ViewHolder();
            holder.account = (TextView) view.findViewById(R.id.item_account);
            holder.name = (TextView) view.findViewById(R.id.item_accountname);
            holder.box = (CheckBox) view.findViewById(R.id.item_accountbox);
            holder.delete = (TextView) view.findViewById(R.id.acount_delete);
            holder.edit = (TextView) view.findViewById(R.id.acount_tvEdit);
            view.setTag(holder);

        }else {
            view=convertView;
            holder= (ViewHolder) view.getTag();
        }
        holder.name.setText(acountlist.get(position).getRealName());
        holder.account.setText(acountlist.get(position).getPayeeAccount());
        if (acountlist.get(position).isChecked()){
            holder.box.setChecked(true);
        }else {
            holder.box.setChecked(false);
        }
        holder.delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenerDelete(position);
                }
            }
        });
        holder.edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListenerEditOrDelete!=null){
                    onClickListenerEditOrDelete.OnClickListenerEdit(position);
                }
            }
        });
        notifyDataSetChanged();
        return view;
    }
    class ViewHolder{
        TextView name,account;
        CheckBox box;
        TextView edit,delete;
    }
    public interface OnClickListenerEditOrDelete{
        void OnClickListenerEdit(int position);
        void OnClickListenerDelete(int position);

    }

    public void setOnClickListenerEditOrDelete(OnClickListenerEditOrDelete onClickListenerEditOrDelete){
        this.onClickListenerEditOrDelete=onClickListenerEditOrDelete;
    }
}
